package com.softcits.email.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.softcits.email.quartz.QuartzBean;

@Repository
public class JobDao {
    
    @Autowired
    private JdbcTemplate template;
    
    public List<QuartzBean> listQuartzBean(String name) {
        String sql = "SELECT job.JOB_NAME as jobName,\r\n" + 
                "        job.JOB_GROUP as jobGroup,\r\n" + 
                "        job.DESCRIPTION as description,\r\n" + 
                "        job.JOB_CLASS_NAME as jobClassName,\r\n" + 
                "        cron.CRON_EXPRESSION as cronExpression,\r\n" + 
                "        tri.TRIGGER_NAME as triggerName,\r\n" + 
                "        tri.TRIGGER_STATE as triggerState,\r\n" + 
                "        job.JOB_NAME as oldJobName,\r\n" + 
                "        job.JOB_GROUP as oldJobGroup\r\n" + 
                "        FROM qrtz_job_details AS job\r\n" + 
                "        LEFT JOIN qrtz_triggers AS tri ON job.JOB_NAME = tri.JOB_NAME\r\n" + 
                "        LEFT JOIN qrtz_cron_triggers AS cron ON cron.TRIGGER_NAME = tri.TRIGGER_NAME\r\n" + 
                "        WHERE tri.TRIGGER_TYPE = 'CRON'";
        List<QuartzBean> list = this.template.query(sql, new BeanPropertyRowMapper(QuartzBean.class));
        System.out.println(sql);
        return list;
    } 
}

